package com.yuhanginfo.modules.web.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.yuhanginfo.common.persistence.Page;
import com.yuhanginfo.common.service.WebCrudService;
import com.yuhanginfo.modules.web.dao.ShoppingCartDao;
import com.yuhanginfo.modules.web.entity.ShoppingCart;

/**
 * 购物车Service
 * @author lvls
 * @version 2017-10-23
 */
@Service
@Transactional(readOnly = true)
public class ShoppingCartService extends WebCrudService<ShoppingCartDao, ShoppingCart> {

	@Autowired
	private ShoppingCartDao shoppingCartDao;
	
	public ShoppingCart get(String id) {
		return super.get(id);
	}
	
	public List<ShoppingCart> findList(ShoppingCart shoppingCart) {
		return super.findList(shoppingCart);
	}
	
	public Page<ShoppingCart> findPage(Page<ShoppingCart> page, ShoppingCart shoppingCart) {
		return super.findPage(page, shoppingCart);
	}
	
	@Transactional(readOnly = false)
	public void save(ShoppingCart shoppingCart) {
		super.save(shoppingCart);
	}
	
	@Transactional(readOnly = false)
	public void delete(ShoppingCart shoppingCart) {
		super.delete(shoppingCart);
	}

	public List<Map<String,Object>> selectGoodsByUserId(ShoppingCart shoppingCart) {
		return shoppingCartDao.selectGoodsByUserId(shoppingCart);
	}

	public List<ShoppingCart> selectInvalidGoods(ShoppingCart shoppingCart) {
		return shoppingCartDao.selectInvalidGoods(shoppingCart);
	}

	public void changeNum(ShoppingCart shoppingCart) {
		shoppingCartDao.changeNum(shoppingCart);
	}
	
	public void changeCheck(ShoppingCart shoppingCart) {
		shoppingCartDao.changeCheck(shoppingCart);
	}

	public List<ShoppingCart> selectByUserId(String idOrCode) {
		return shoppingCartDao.selectByUserId(idOrCode);
	}

	public List<ShoppingCart> selectByStoreCode(String idOrCode) {
		return shoppingCartDao.selectByStoreCode(idOrCode);
	}

	public List<ShoppingCart> selectCheckByCodesAndUserId(Map<String,Object> map) {
		return shoppingCartDao.selectCheckByCodesAndUserId(map);
	}

	public List<ShoppingCart> selectByids(String[] split) {
		return shoppingCartDao.selectByids(split);
	}

	/**
	 * 通过userId goodsCode storeCode来判断数据库中是否有该商品
	 */
	public ShoppingCart selectByStoreCodeAndGoodsCodeAndUserId(ShoppingCart shoppingCart) {
		return shoppingCartDao.selectByStoreCodeAndGoodsCodeAndUserId(shoppingCart);
	}
	
}